package com.ruoyi.finance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.finance.domain.CenterTable;
import com.ruoyi.finance.service.ICenterTableService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模版类型表Controller
 *
 * @author ruoyi
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/finance/tablecenter")
public class CenterTableController extends BaseController
{
    @Autowired
    private ICenterTableService centerTableService;

    /**
     * 查询模版类型表列表
     */
    @PreAuthorize("@ss.hasPermi('finance:tablecenter:list')")
    @GetMapping("/list")
    public TableDataInfo list(CenterTable centerTable)
    {
        startPage();
        List<CenterTable> list = centerTableService.selectCenterTableList(centerTable);
        return getDataTable(list);
    }

    @GetMapping("/tolist")
    public TableDataInfo tolist(CenterTable centerTable)
    {
        startPage();
        List<CenterTable> list = centerTableService.selectolist(centerTable);
        return getDataTable(list);
    }


    /**
     * 导出模版类型表列表
     */
    @PreAuthorize("@ss.hasPermi('finance:tablecenter:export')")
    @Log(title = "模版类型表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CenterTable centerTable)
    {
        List<CenterTable> list = centerTableService.selectCenterTableList(centerTable);
        ExcelUtil<CenterTable> util = new ExcelUtil<CenterTable>(CenterTable.class);
        util.exportExcel(response, list, "模版类型表数据");
    }

    /**
     * 获取模版类型表详细信息
     */
    @PreAuthorize("@ss.hasPermi('finance:tablecenter:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(centerTableService.selectCenterTableById(id));
    }

    /**
     * 新增模版类型表
     */
    @PreAuthorize("@ss.hasPermi('finance:tablecenter:add')")
    @Log(title = "模版类型表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CenterTable centerTable)
    {
        return toAjax(centerTableService.insertCenterTable(centerTable));
    }

    /**
     * 修改模版类型表
     */
    @PreAuthorize("@ss.hasPermi('finance:tablecenter:edit')")
    @Log(title = "模版类型表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CenterTable centerTable)
    {
        return toAjax(centerTableService.updateCenterTable(centerTable));
    }

    /**
     * 删除模版类型表
     */
    @PreAuthorize("@ss.hasPermi('finance:tablecenter:remove')")
    @Log(title = "模版类型表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(centerTableService.deleteCenterTableByIds(ids));
    }
}
